#ifndef MEMORYMANAGER_H_
#define MEMORYMANAGER_H_

#include <malloc.h>
#include "constants.h"
#include <iostream>

class MemoryManager
{
public:
	~MemoryManager();
 
	template<class M> char* request(const int amount)
	{
//		std::cout << cur + amount + 1 << std::endl;
//		std::cout << size << std::endl;
		if (cur + (amount * (int)sizeof(M)) + 1 >= size)
		{ // we need to reallocate
//			size += RESIZE;
//			data = (M*)realloc(data, sizeof(M) * size);
			/**
			 * HACK
			 */
			std::cout << "Memory-request failed!" << std::endl;
			exit(-1);
		}

		cur += (amount * sizeof(M));
		return &(data[cur - (amount * sizeof(M))]);
	}

	void clear(void)
	{
		cur = 0;
	}
	
	inline int getUsed(void) const
	{
		return cur;
	}
	
protected:
	char* data;
	int size;
	int cur;

	const int RESIZE;
	
	MemoryManager(const int is, const int rs);
private:

	MemoryManager(const MemoryManager& copy) : RESIZE(copy.RESIZE)
	{
	}
};

#endif /*MEMORYMANAGER_H_*/
